"use strict";

const Controller = require("egg").Controller;

class adminLoginController extends Controller {
  async index() {
    this.ctx.body = "hello";
  }

  // post请求 用户注册
  async adminRegister() {
    try {
      let res = await this.ctx.service.adminLogin.register();
      if (res) {
        this.ctx.body = {
          code: 200,
          data: res
        };
      }
    } catch (e) {
      this.ctx.body = {
        code: 400,
        data: {
          msg: "错误"
        }
      };
    }
  }

  async adminUpdate() {
    try {
      let res = await this.ctx.service.adminLogin.update();
      if (res) {
        this.ctx.body = {
          code: 200,
          data: res
        };
      }
    } catch (e) {
      this.ctx.body = {
        code: 400,
        data: {
          msg: "错误"
        }
      };
    }
  }

  //用户登录
  async adminSignIn() {
    try {
      let res = await this.ctx.service.adminLogin.signIn();
      if (res) {
        this.ctx.body = {
          code: 200,
          data: res
        };
      }
    } catch (e) {
      this.ctx.body = {
        code: 400,
        data: {
          msg: "错误"
        }
      };
    }
  }
}

module.exports = adminLoginController;
